import { request, API_BASE_URL } from '@/utils/http';

// 报销申请接口参数类型
export interface ExpenseRequest {
  amount: number; // 报销金额
  amountDate: string; // 费用发生日期
  amountType: string; // 报销类型
  amountRemark: string; // 报销明细/备注
}

// 报销申请响应类型
export interface ExpenseResponse {
  msg: string; // 响应消息
  code: number; // 响应状态码
  data?: {
    id: string; // 报销申请ID
    type: string; // 类型标识
  }
}

/**
 * 提交报销申请
 * @param data 报销申请数据
 * @returns Promise<ExpenseResponse>
 */
export const addBaoXiao = async (data: ExpenseRequest): Promise<ExpenseResponse> => {
  try {
    return await request(`${API_BASE_URL}/OA/contract/addBaoXiao`, {
      method: 'POST',
      data: data,
    });
  } catch (error) {
    console.error('提交报销申请失败:', error);
    throw error;
  }
};

/**
 * 获取报销列表
 * @param params 查询参数
 * @returns Promise<any>
 */
export const getExpenseList = async (params?: any): Promise<any> => {
  try {
    return await request(`${API_BASE_URL}/OA/contract/expenseList`, {
      method: 'GET',
      params: params,
    });
  } catch (error) {
    console.error('获取报销列表失败:', error);
    throw error;
  }
};

/**
 * 获取报销详情
 * @param id 报销ID
 * @returns Promise<any>
 */
export const getExpenseDetail = async (id: string): Promise<any> => {
  try {
    return await request(`${API_BASE_URL}/OA/contract/expenseDetail/${id}`, {
      method: 'GET',
    });
  } catch (error) {
    console.error('获取报销详情失败:', error);
    throw error;
  }
};

/**
 * 撤销报销申请
 * @param id 报销ID
 * @returns Promise<any>
 */
export const cancelExpense = async (id: string): Promise<any> => {
  try {
    return await request(`${API_BASE_URL}/OA/contract/cancelExpense`, {
      method: 'POST',
      data: { id },
    });
  } catch (error) {
    console.error('撤销报销申请失败:', error);
    throw error;
  }
};